package com.nercel.dsj.gksales.service.impl;

import com.nercel.dsj.gksales.dao.mapper.RegionPayCodeMapper;
import com.nercel.dsj.gksales.model.QueryParams;
import com.nercel.dsj.gksales.model.entity.RegionPayCode;
import com.nercel.dsj.gksales.service.RegionPayCodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class RegionPayCodeServiceImpl implements RegionPayCodeService {

	private final RegionPayCodeMapper regionPayCodeMapper;

    @Override
    public List<RegionPayCode> list(QueryParams queryParams) {
        return regionPayCodeMapper.query(queryParams);
    }

    @Override
    public List<RegionPayCode> listByRegionId(Integer regionId) {
        QueryParams queryParams = new QueryParams();
        queryParams.put("regionId", regionId);
        return regionPayCodeMapper.query(queryParams);
    }


    @Transactional
    @Override
    public void deleteByRegionId(Integer regionId) {
        List<RegionPayCode> list = listByRegionId(regionId);
        list.forEach(item->{
            delete(item.getId());
        });
    }

    @Override
    public void save(RegionPayCode regionPayCode) {
        regionPayCodeMapper.insertSelective(regionPayCode);
    }

    @Override
    public void update(RegionPayCode regionPayCode) {
        regionPayCodeMapper.updateByPrimaryKeySelective(regionPayCode);
    }

    @Override
    public RegionPayCode findById(Integer integer) {
        return regionPayCodeMapper.selectByPrimaryKey(integer);
    }

    @Override
    public List<RegionPayCode> listAll() {
        return regionPayCodeMapper.query(new QueryParams());
    }

    @Override
    public void delete(Integer integer) {
        regionPayCodeMapper.deleteByPrimaryKey(integer);
    }

}
